

const mongoose = require('mongoose');

var express = require('express')
// 注意这里的声明
var resume = express()
// const controller= require("../../controller/controllerenter")


const {createResponse}= require("../../util/createResponse/index");
const {businessCodes}= require("../../code/businessCodes/index");
const {resumeService } = require('../../service/impl/resumeService/index');
// const { resume_bean } = require('../../beans/impl/resume_bean/index');


resume.post('/post/resume/add', async (req,res) => {
  let result
  try {
    let news  = req.body.news
    result =  await resumeService.getIns().create(news)
  } catch (error) {
    console.log(error);
    createResponse(res,500,businessCodes.b2)
    return
  }
    createResponse(res,200,businessCodes.b1,result)
  })



  

  // 无则新增有则修改简历信息
  resume.post('/post/resume/updateAndAdd', async (req,res) => {
    let result
    let options = {
      "new":true,
      "upsert":true,
      "runValidators":true,
    }
    try {
      let  userid  = req.body.conditions.userid
      let updates = req.body.updates
      result =  await resumeService.getIns().findOneAndUpdate(conditions,updates,options)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
    createResponse(res,200,businessCodes.b1,result)
  })


  // 根据用户id,查询该用户的简历
  resume.post('/post/resume/queryByUserid', async (req,res) => {
    let result
    try {
      let conditions  = req.body.conditions
      result =  await resumeService.getIns().findOne(conditions)
    } catch (error) {
      console.log(error);
      createResponse(res,500,businessCodes.b2)
      return
    }
     if(result){
      createResponse(res,200,businessCodes.b1,result)
     }else{
      createResponse(res,200,businessCodes.b3,result)
     }
    })
  

  
  module.exports= resume